package com.kiloai.base.utils;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;

/**
 * Created by david on 17/7/4.
 */

public class DrawableUtil {

    /**
     * 通过fileName 字符串，获取对应drawable下的id
     *
     * @param fileName
     * @return
     */
    public static int getDrawableIdByStr(Context context, String fileName) {

        Resources res = context.getResources();
        return res.getIdentifier(fileName, "drawable", context.getPackageName());
    }


    /**
     * 改变drawable的颜色
     *
     * @param drawable
     * @param color
     * @return
     */
    public static Drawable tintDrawable(Drawable drawable, int color) {
        Drawable wrappedDrasable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(wrappedDrasable, ColorStateList.valueOf(color));
        return wrappedDrasable;
    }
}
